﻿/*---------------------------------------------------------------------*/
// fileName="NotifyService.cs" CompanyName="SureKAM"
// Copyright SureKAM (c). All right reserved.
/*---------------------------------------------------------------------*/

namespace SureKAM.BackUp.Notify.Service
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SureKAM.BackUp.Notify.Service.Interfaces;
    using Microsoft.Practices.Unity;
    using SureKAM.BackUp.Notify.DataAccess;

    /// <summary>
    /// Notify服务类
    /// </summary>
    public class NotifyService : INotifyService
    {
        #region 私有字段
        private INotify notifyDataAccess;
        #endregion

        #region 构造方法
        /// <summary>
        /// 构造方法
        /// </summary>
        public NotifyService()
        {
            notifyDataAccess = DataAccessIOC.Current.Resolve<INotify>();
        }
        #endregion

        #region 公有方法
        /// <summary>
        /// 添加Notify对象
        /// </summary>
        /// <param name="notify">notify对象</param>
        /// <returns>返回notify id</returns>
        public string Add(Domain.Notify notify)
        {
            string notifyId = notifyDataAccess.InsertNotify(notify);
            notifyDataAccess.SaveToFile();
            return notifyId;
        }

        /// <summary>
        /// 更新notify对象
        /// </summary>
        /// <param name="notify">notify对象</param>
        /// <returns>更新后的notify</returns>
        public Domain.Notify Update(Domain.Notify notify)
        {
            Domain.Notify updateNotify = notifyDataAccess.UpdateNotify(notify);
            notifyDataAccess.SaveToFile();
            return updateNotify;
        }

        /// <summary>
        /// 删除notify对象
        /// </summary>
        /// <param name="notify">notify</param>
        /// <returns></returns>
        public string Delete(Domain.Notify notify)
        {
            bool operation = notifyDataAccess.DeleteNotify(notify.ID);
            notifyDataAccess.SaveToFile();
            return operation ? notify.ID : string.Empty;
        }

        /// <summary>
        /// 根据ID获取Notify对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Domain.Notify GetNotifyById(string id)
        {
            return notifyDataAccess.GetNotifyById(id);
        }

        /// <summary>
        /// 获取所有的Notify对象
        /// </summary>
        /// <returns></returns>
        public List<Domain.Notify> GetNotifies()
        {
            return notifyDataAccess.GetNotifys();
        }
        #endregion
    }
}
